import { createStore,applyMiddleware } from "redux";
import thunk from 'redux-thunk';
import cartReducer from "./cart";
import userReducer from "./user";
import { combineReducers } from "redux";
import {persistStore, persistReducer} from 'redux-persist';
import storageSession from 'redux-persist/lib/storage/session';
 
// store持久化设置
const storageConfig = {
    key: 'root', // 必须有的
    storage:storageSession, // 缓存机制
    blacklist: [] // reducer 里不持久化的数据,除此外均为持久化数据
}
// 合并reducer
const reduceList = combineReducers({ user: userReducer, cart:cartReducer });
// 给reducer应用持久化配置
const newReducers = persistReducer(storageConfig, reduceList);
// 创建store
const store = createStore(newReducers,applyMiddleware(thunk));
// 对store进行持久化并导出
export const persistor = persistStore(store);
export default store;
